package cn.edu.scau.cmi.lixiaoyuan.client;

import java.util.Scanner;

import cn.edu.scau.cmi.lixiaoyuan.composite.consistent.ConsistentOrganization;
import cn.edu.scau.cmi.lixiaoyuan.composite.consistent.Person;
import cn.edu.scau.cmi.lixiaoyuan.composite.consistent.Team;
import cn.edu.scau.cmi.lixiaoyuan.composite.safe.SafeOrganization;
import cn.edu.scau.cmi.lixiaoyuan.composite.safe.SafePerson;
import cn.edu.scau.cmi.lixiaoyuan.composite.safe.SafeTeam;

public class SafeCompositeClient {
	public static SafeTeam trank = new SafeTeam ("根目录");

	public static void createTeam(String name) {
		SafeTeam team = new SafeTeam(name);
		trank.addTeam(team);
		
	}
	public static void addToTeam(String name,SafeTeam safeteam) {
		SafePerson person = new SafePerson(name);
		safeteam.addPerson(person, safeteam);
		
	}
//	
	public static SafeOrganization findTeam(String name) {
       for(Object obj :trank.safeTeams) {
    	   
			if((((SafeTeam)obj).getName()).equals(name)) {
				return (SafeTeam) obj;
			}
		}
	return null;
		
	}
//	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		System.out.println("1.输入组，2.添加组员，其他键输出");
		int judge = sc.nextInt();
		
		
		while(judge==1||judge==2) {
			if(judge==1) {
				System.out.print("请输入组名:");
				
				String name1 = sc.next();
				createTeam(name1);
			}else if(judge == 2){
				System.out.print("请输入组名:");
				
				String name1 = sc.next();
				
				if(findTeam(name1)==null) {
					System.out.println("不存在该队伍");
				}else {
					System.out.print("输入组员名字：");
					String name2 = sc.next();
					
					addToTeam(name2, (SafeTeam) findTeam(name1));
				}
			}
			
			System.out.println("1.输入组，2.添加组员，其他键输出");
			judge = sc.nextInt();
		}
	    sc.close();
		trank.doSomething();
}
}
